<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>

var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
canvas.setAttribute('width', '700');
canvas.setAttribute('height', '700');
var ctx = canvas.getContext('2d');
var initialLineDash = [1.5, 2.5];
var initialLineDashOffset = 1.5;

function resetLineDash() {
    ctx.setLineDash(initialLineDash);
    ctx.lineDashOffset = initialLineDashOffset;
}

function trySettingLineDash(value) {
    resetLineDash();
    ctx.setLineDash(value);
    return ctx.getLineDash();
}

function trySettingLineDashWithNoArgs() {
    resetLineDash();
    ctx.setLineDash();
    return ctx.getLineDash();
}

function trySettingLineDashOffset(value) {
    resetLineDash();
    ctx.lineDashOffset = value;
    return ctx.lineDashOffset;
}

test(function(t) {
    assert_array_equals(trySettingLineDash([1, -1]), initialLineDash);
    assert_array_equals(trySettingLineDash([1, Infinity]), initialLineDash);
    assert_array_equals(trySettingLineDash([1, -Infinity]), initialLineDash);
    assert_array_equals(trySettingLineDash([1, NaN]), initialLineDash);
    assert_array_equals(trySettingLineDash([1, 'string']), initialLineDash);
    assert_throws_js(TypeError, function() {
      trySettingLineDashWithNoArgs();
    });

    assert_equals(trySettingLineDashOffset(Infinity), initialLineDashOffset);
    assert_equals(trySettingLineDashOffset(-Infinity), initialLineDashOffset);
    assert_equals(trySettingLineDashOffset(NaN), initialLineDashOffset);
    assert_equals(trySettingLineDashOffset('string'), initialLineDashOffset);
}, "Test for invalid input of setLineDash, getLineDash and lineDashOffset");
</script>
</body>
